import datetime
import json
import os

from config import owner_department


def get_user_list():
    cmd = 'cd /d d:/Program Files/apache-maven-3.8.1-bin/ins-scm-internal&mvn clean test -e "-Dtest=com.liepin.scm.internal.tickets.helper.GitlabClientHelperTest#projectInfo" "-DSystemRuntimeEnvironment=qa" "-Darea=QAPUB" "-Dconfig.client_id=20170" "-Dsurefire.useFile=false"'
    # # cmd = 'cd /d d:/Program Files/apache-maven-3.8.1-bin/ins-scm-internal&dir'
    cmd_popen = os.popen(cmd)
    # cmd_popen.buffer.read().decode(encoding='UTF-8')
    # print(cmd_popen.read())
    datalist = cmd_popen.readlines()
    # print('datalist', datalist)
    cmd_popen.close()
    start_index = datalist.index('=====\n')
    end_index = datalist.index('+++++\n')
    datalist_1 = datalist[start_index + 2:end_index - 2]
    datalist_2 = []
    for i in datalist_1:
        new_i = i.strip('[')
        new_i = json.loads(new_i.strip(',\n'))
        for j in range(len(owner_department)):
            if new_i['owner'] == owner_department[j].get('owner'):
                new_i['department'] = owner_department[j].get('department')
            elif new_i['owner'] == '':
                new_i['department'] = ''
        datalist_2.append(new_i)
    # print(len(datalist_2), datalist_2)
    return datalist_2

if __name__ == '__main__':
    # file = '2021-5-25.xlsx'
    # file = '敏感信息调用-2021年6月8日.xlsx'
    # wb = openpyxl.load_workbook(file)
    start = datetime.datetime.now()
    get_user_list()
    # new_data(1)
    # history_data(0)
    # unique_data(0, 1)
    end = datetime.datetime.now()
    print('运行时间统计：', (end - start).seconds)